import { StringOrNull } from '../Types';
import { IValidator } from './IValidator';


/**
 * 验证字符串长度是否满足要求。
 * 1. 字符串为null 时返回 false
 * 2. 字符串长度不等于指定长度时返回 false
 */
export class FixedLengthValidator implements IValidator<StringOrNull> {
    private fixedLength: number;
    constructor(fixedLength: number) {
        this.fixedLength = fixedLength;
    }
    public IsValid(input: StringOrNull): boolean {
        if (!input) {
            return false;
        }
        return input.length == this.fixedLength;
    }
}